package cn.hanyx.coder.design.pattern.structural.proxy.demo01;

/**
 * UserControllerProxy
 *
 * @author hanyx
 * @date 2020/05/18
 */
public class UserControllerProxy implements IUserController {

    private UserController userController;
    private MetricsCollector metricsCollector;

    public UserControllerProxy(UserController userController) {
        this.userController = userController;
        this.metricsCollector = new MetricsCollector();
    }

    @Override
    public UserVo login(String phone, String password) {
        UserVo userVo = userController.login(phone, password);
        metricsCollector.recordRequest();
        return userVo;
    }

    @Override
    public UserVo register(String phone, String password) {
        UserVo userVo = userController.register(phone, password);
        metricsCollector.recordRequest();
        return userVo;
    }

    public static void main(String[] args) {
        IUserController userController = new UserControllerProxy(new UserController());
        userController.login("213","hanyx");
    }
}
